/*
 * Copyright 2011 yura.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.opu.db_vdumper.ui;

import net.infonode.docking.theme.BlueHighlightDockingTheme;
import net.infonode.docking.theme.ClassicDockingTheme;
import net.infonode.docking.theme.DefaultDockingTheme;
import net.infonode.docking.theme.DockingWindowsTheme;
import net.infonode.docking.theme.GradientDockingTheme;
import net.infonode.docking.theme.ShapedGradientDockingTheme;
import net.infonode.docking.theme.SlimFlatDockingTheme;
import net.infonode.docking.theme.SoftBlueIceDockingTheme;
import net.infonode.tabbedpanel.theme.ClassicTheme;
import net.infonode.tabbedpanel.theme.GradientTheme;
import org.opu.db_vdumper.util.Logger;
import org.opu.db_vdumper.util.StringUtil;

/**
 *
 * @author yura
 */
public class ThemeManager {
    public static final String BLUE_HIGHLIGHT_THEME = "Blue Highlight Theme";
    public static final String CLASSIC_THEME = "Classic Theme";
    public static final String DEFAULT_THEME = "Default Theme";
    public static final String SHAPED_GRADIENT_DOCKING_THEME = "Shaped Gradient Docking Theme";
    public static final String SHAPED_GRADIENT_THEME = "Shaped Gradient Theme";
    public static final String SLIM_FLAT_THEME = "Slim Flat Theme";
    public static final String SOFT_BLUE_ICE_THEME = "Soft Blue Ice Theme";

    public static DockingWindowsTheme[] themes(){
        return new DockingWindowsTheme[] {new DefaultDockingTheme(),
            new BlueHighlightDockingTheme(), new SlimFlatDockingTheme(),
            new GradientDockingTheme(), new ShapedGradientDockingTheme(),
            new SoftBlueIceDockingTheme(), new ClassicDockingTheme()};
    }

    public static DockingWindowsTheme defaultTheme(){
        return new ShapedGradientDockingTheme();
    }

    public static DockingWindowsTheme getTheme(String name) throws ThemeException{
        Logger.getInstance().debug(ThemeManager.class, "Call name to theme ("
                + name + ")");

        if (!StringUtil.ifStr(name)){
            throw new ThemeException("Thme name can't be null");
        }

        DockingWindowsTheme ret = null;

        if (DEFAULT_THEME.equals(name)){
            ret = new DefaultDockingTheme();
        } else if (BLUE_HIGHLIGHT_THEME.equals(name)){
            ret = new BlueHighlightDockingTheme();
        } else if (SLIM_FLAT_THEME.equals(name)){
            ret = new SlimFlatDockingTheme();
        } else if (SHAPED_GRADIENT_DOCKING_THEME.equals(name)){
            ret = new GradientDockingTheme();
        } else if (SHAPED_GRADIENT_THEME.equals(name)){
            ret = new ShapedGradientDockingTheme();
        } else if (SOFT_BLUE_ICE_THEME.equals(name)){
            ret = new SoftBlueIceDockingTheme();
        } else if (CLASSIC_THEME.equals(name)){
            ret = new ClassicDockingTheme();
        } else {
            throw new ThemeException("Unreachable theme: " + name);
        }

        Logger.getInstance().debug(ThemeManager.class, "Return \""
                + ret.getClass() + "\"");

        return ret;
        
    }
    
    public static String getName(DockingWindowsTheme theme) throws ThemeException{
        if (theme == null){
            throw new ThemeException("Them can't be null!");
        }

        Logger.getInstance().debug(ThemeManager.class, "Call theme to name ("
                + theme.getClass() + ")");

        String ret = theme.getName();

        if (DefaultDockingTheme.class == theme.getClass()){
            ret = DEFAULT_THEME;
        } else if (BlueHighlightDockingTheme.class == theme.getClass()){
            ret = BLUE_HIGHLIGHT_THEME;
        } else if (SlimFlatDockingTheme.class == theme.getClass()){
            ret = SLIM_FLAT_THEME;
        } else if (GradientDockingTheme.class == theme.getClass()){
            ret = SHAPED_GRADIENT_DOCKING_THEME;
        } else if (ShapedGradientDockingTheme.class == theme.getClass()){
            ret = SHAPED_GRADIENT_THEME;
        } else if (SoftBlueIceDockingTheme.class == theme.getClass()){
            ret = SOFT_BLUE_ICE_THEME;
        } else if (ClassicDockingTheme.class == theme.getClass()){
            ret = CLASSIC_THEME;
        } else {
            throw new ThemeException("Unsupported theme: " + theme.getClass());
        }

        Logger.getInstance().debug(ThemeManager.class, "Return \"" + ret + "\"");

        return ret;
    }

    public static class ThemeException extends Exception {

        public ThemeException(Throwable cause) {
            super(cause);
        }

        public ThemeException(String message, Throwable cause) {
            super(message, cause);
        }

        public ThemeException(String message) {
            super(message);
        }

        public ThemeException() {
        }


    }
}
